#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main()
{
    FILE* fp = fopen("log.txt", "r");
    if (!fp)
    {
        perror("fopen");
    }
    char buf[30];
    memset(buf,'c', 30);
    const char *msg = "hello Linux message\n";
    while (1)
    {
        // 注意返回值和参数，此处有坑，仔细查看man手册关于该函数的说明
        size_t s = fread(buf, 1, strlen(msg), fp);
        if (s > 0)
        {
            buf[s] = 0;
            printf("%s", buf);
        }
        if (feof(fp))
        {
            break;
        }
        sleep(1);
    }
    
    fclose(fp);
    return 0;
}


